const fs = require('fs');  
const { app,clipboard,shell } = require("electron");
const Router = require('koa-router') 
const router = new Router()

const child = require('child_process')
var path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
  
router.post('/api/host', async function(ctx, next) {
    let { host } = ctx.request.body 
    if(host){ 
        fs.writeFileSync(path, host);
    }else{
        host = fs.readFileSync(path,{encoding:'utf8', flag:'r'});
    }
    ctx.body = {  host }
}) 

router.post('/api/open', async function(ctx, next) { 
    child.exec("notepad " + path, (err, stdout, stderr) => {  }) 
    ctx.body = { data:path  }
}) 


module.exports = router
 